package models

import "math"

// // 性能测试用
// type Document struct {
// 	Id    int    `db:"id"`
// 	Title string `db:"title"`
// 	//FilePath string `db:"file_path"`
// 	Content string `db:"text"`
// }

type PlainDocument struct {
	Id       int    `db:"id"`
	Title    string `db:"title"`
	FileType string `db:"file_type"`
	FilePath string `db:"file_path"`
	// Content  string
}

type EncDocument struct {
	Id          int    `db:"id"`
	EncTitle    []byte `db:"enc_title"`
	EncFileType []byte `db:"enc_file_type"`
	EncFilePath string `db:"enc_file_path"`
}

type TermDocItem struct {
	DocId int
	Freq  int
}

type PlainTermItem struct {
	TermId int    `db:"term_id"`
	Term   string `db:"term"`
}

type PlainIndexItem struct {
	TermId  int `db:"term_id"`
	TermLen int `db:"term_len"`
	DocId   int `db:"doc_id"`
	Freq    int `db:"freq"`
}

type IndexItem struct {
	TermId  int    `db:"term_id"`
	TermLen int    `db:"term_len"`
	DocId   int    `db:"doc_id"`
	EncFreq []byte `db:"enc_freq"`
	// freq    int
	// tfidf   float64
}

type TermItem struct {
	TermId  int    `db:"term_id"`
	Bucket8 int    `db:"bucket8"`
	FheTerm []byte `db:"fhe_term"`
}

type EncDocInfoItem struct {
	DocId       int     `db:"doc_id" json:"doc_id"`
	EncFreq     []byte  `db:"enc_freq" json:"-"`
	EncTitle    []byte  `db:"enc_title" json:"-"`
	EncFilePath string  `db:"enc_file_path" json:"-"`
	EncFileType []byte  `db:"enc_file_type" json:"-"`
	Freq        int     `db:"-" json:"-"`
	TFIDF       float64 `db:"-" json:"-"`
	Title       string  `db:"-" json:"title"`
	FileType    string  `db:"-" json:"file_type"`
}

const TotalDocNum = 2000_000

func (item *EncDocInfoItem) SetTFIDF(df int) {
	tf := item.Freq
	idf := math.Log(TotalDocNum / float64(df+1))
	item.TFIDF = float64(tf) * idf
}
